<?php
require('connection.php');

session_start();


if(!isset( $_SESSION['ok']))
	 $_SESSION['ok'] = 0;

if(!isset( $_SESSION['error']))
	 $_SESSION['error'] = 0;
	
if(isset($_POST['antworten'])){

	$original =  ($_SESSION['res']['question']);
	$userAnswer =  ($_POST['antworten']); 
	$answer =  ($_SESSION['res']['answer']);
	$detail =  ($_SESSION['res']['detail']);
		
	if( $userAnswer == $answer){
		
		$_SESSION['ok']++;
		$flag = true;
		
	}else{

		$_SESSION['error']++;
		$flag = false;
	}// fim do errou
	
}// fim do tem post


$sql = "select * from flashes order by rand() limit 0,1";
$stm = $conn->prepare($sql);
$stm->execute();
$_SESSION['res'] = $stm->fetch();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Das frage</title>
</head>
<body>
	
	<p>
	<span style="color: blue;">Recht: <?php echo($_SESSION['ok']); ?></span> | <span style="color: red;">Fehler: <?php echo($_SESSION['error']); ?></span>
	<?php if(isset($answer)) { ?>
		<br/>
		<b>vorherige Frage:</b> <?php echo($original); ?> <br/>
		<b>Ihre Antwort:</b> <?php echo($userAnswer); ?> <br/>
		<b>Ergebnis:</b> <?php echo(($flag)?'RECHT':'FALSCH'); ?> <br/>
		<b>Richtige Antwort:</b> <?php echo($answer); ?> <br/>
		<b>Beschreibung:</b> <?php echo($detail); ?>
	<?php } ?>  	
	</p>
	<hr/>

	<p style="font-size: 80px;font-weight: bold;text-align: center;">
		<?php echo(($_SESSION['res']['question'])); ?>
	</p>
	<form method="post">
		<p align="center">
			Das Antworten<br/>
			<input type="text" name="antworten" id="sindIch" autocomplete="off" style="height: 40px; width: 400px; font-size: 30px; font-weight: bold;">
			<br/>
			<input name="nachste" value="Antworten!" type="submit">
		</p>
	</form>
	<script>
		document.getElementById('sindIch').focus();
	</script>
</body>
</html>